package torres.item.interactive;


import torres.controller.Command;
import torres.entity.Avatar;
import torres.entity.Entity;
import torres.map.Location;
import torres.map.Map;
import torres.map.World;

/**
 * @author Torres
 * An interaction that moves the Entity to a new Location on a 
 * (possibly different) map.
 */
@SuppressWarnings("serial")
public class Teleporter implements Interaction {
	
	private String mapString;
	private Map map;
	private Location toLocation;
	
	
	/**
	 * Creates a new Teleporter to the specified Location on the specified Map.
	 * @param mapString The name of the map to be teleported to.
	 * @param toLocation The location on the map to be teleported to.
	 */
	public Teleporter(String mapString, Location toLocation) {
		
		this.mapString = mapString;
		this.toLocation = toLocation;
	}
	
	/**
	 * Return the destination Map of this Teleporter.
	 */
	public Map getMap() {
		
		return map;
	}
	
	/**
	 * Set the destination Map of this Teleporter.
	 * @param The Map that the Teleporter will be associated with. 
	 */
	public void setMap(Map map) {
		
		this.map = map;
	}
	
	/**
	 * Use this interaction on the specified entity.
	 * @param The Entity that is using this Interaction. 
	 */
	public void use(Entity e) {
		if(map == null) {
			map = World.getInstance().getMap(mapString);
		}
		Command.teleport((Avatar) e, map, toLocation);
	}
	
	
	/** 
	 * Returns the String representation of this Teleporter.
	 * @return The String representation of this Teleporter.
	 */
	public String toString() {
		return "teleportInteraction";
	}
}
